function foot2inches(value) {
    
    if (value*12 != 0)
        return value = value*12;
    return 0;
} 
function foot2cm(value) {
	
    if (value* 30.48 != 0){
        return  value* 30.48;
		}
    return 0;
}
function inch2cm(value) {
    
    if (value*2.54 != 0)
        return value*2.54;
    return 0;
}
function inch2foot(value) {
    
    if (value/12 != 0)
        return value/12;
    return 0;
}
function cm2foot(value) {
    
    if (value*0.0328083989501 != 0)
        return value = value*0.0328083989501;
    return 0;
}

function cm2inches(value) {
    
    if (value*0.393700787402 != 0)
        return value = value*0.393700787402;
    return 0;
}
function loadValueDefault($val){
	var cmSmall= [0,"32","82","72","63","79","89","14","25","55","62","69","162","35","82","143"];
	var cmMedium=[0,"34","88","78","68","84","94","15","27","56","63","72","165","37","84","148"];
	var cmLarge= [0,"37","97","80","75","92","102","17","30","57","65","74","167","40","86","160"];
	
	var $foot=new Object();
	var $inches=new Object();
	if($val=='Large'){
		setValue('cm_',cmLarge);
		for (var i in cmLarge){
		  $foot[i]= cm2foot(cmLarge[i]).toFixed(2);
		  $inches[i]= cm2inches(cmLarge[i]).toFixed(2);
		}
	}
	if($val=='Medium'){
		setValue('cm_',cmMedium);
		for (var i in cmMedium){
		  $foot[i]= cm2foot(cmMedium[i]).toFixed(2);
		  $inches[i]= cm2inches(cmMedium[i]).toFixed(2);
		}
	}
	if($val=='Small'){;
		setValue('cm_',cmSmall);
		for (var i in cmSmall){
		  $foot[i]= cm2foot(cmSmall[i]).toFixed(2);
		  $inches[i]= cm2inches(cmSmall[i]).toFixed(2);
		}
	}
	setValue('foot_',$foot);
	setValue('inches_',$inches);
}
function setValue($id,$array){
	for(var i in $array){
		 $('#'+$id+i).val($array[i]);
	} 
}

jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow point backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
				key == 190 || 
				key == 110 ||
                key == 8 || 
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });
    });
};
function priceProduct(){
	var price=parseFloat($("#price").val());
	var qty=parseInt($("#quantity").val());
	var stone=parseInt($('input:radio[name=stone]:checked').val());
	return price*qty+stone;
}

$(document).ready(function() {

	
	  loadValueDefault('Small');
	$('#SelectSize').change(function() {
	  var $selectVal=$(this).val();
	  loadValueDefault($selectVal);
	});
	
	$('.foot').change(function() {
	  var $Val=$(this).val();	  
	  var $id=$(this).attr( 'id' ).split('_')[1];
	  $('#cm_'+$id).val(foot2cm($Val).toFixed(2));
	  $('#inches_'+$id).val(foot2inches($Val).toFixed(2));
	});
	
	$('.cm').change(function() {
	  var $Val=$(this).val();	  
	  var $id=$(this).attr( 'id' ).split('_')[1];
	  $('#foot_'+$id).val(cm2foot($Val).toFixed(2));
	  $('#inches_'+$id).val(cm2inches($Val).toFixed(2));
	});
	$('.inches').change(function() {
	  var $Val=$(this).val();	  
	  var $id=$(this).attr( 'id' ).split('_')[1];
	  $('#cm_'+$id).val(inch2cm($Val).toFixed(2));
	  $('#foot_'+$id).val(inch2foot($Val).toFixed(2));
	});
	$(".messure input").ForceNumericOnly();

	$("#stone input").change(function() {
		$("#priceProduct").text(priceProduct());
	});
	
});